package com.example.administrator.daggerdemo.yujian.select;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.administrator.daggerdemo.R;
import com.example.administrator.daggerdemo.yujian.HorizontalCalendarView;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * Created by zhengjian on 2016/11/29.
 */
public class MainActivity extends AppCompatActivity {

    RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);
        recyclerView=(RecyclerView)findViewById(R.id.recyler);
        initData();
        initView();
    }

    List<SelectCut> list;
    List<User> userList;
    void initData()
    {
        userList=new ArrayList<>();
        for (int i=0;i<100;i++)
        {
            if(i<50)
            {
                userList.add(new User("1班","name"+i,"age"+i));
            }else
            {
                userList.add(new User("2班","name"+i,"age"+i));
            }

        }
        list=new ArrayList<>();
        String head="";
        for (User user : userList) {

            if(head.equals(user.className))
            {
                list.add(new SelectCut(user));
            }else
            {
                list.add(new SelectCut(true,user.className));
                list.add(new SelectCut(user));
            }
                head=user.className;

        }
    }

    //头部

    public View initHead()
    {
        View v=LayoutInflater.from(this).inflate(R.layout.dddd,null);

        HorizontalCalendarView view=(HorizontalCalendarView)v.findViewById(R.id.aa);
        view.initData();
        view.setOnHCalendarItemClickListener(new HorizontalCalendarView.OnHCalendarItemClickListener() {
            @Override
            public void OnHCalendarItemClick(int position, Date date) {
                Toast.makeText(MainActivity.this,position+"",Toast.LENGTH_LONG).show();
            }
        });
        return v;
    }

    void initView()
    {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        SectionAda  ada=new SectionAda(list);
        ada.removeAllHeaderView();
        ada.addHeaderView(initHead());
        recyclerView.setAdapter(ada);
    }
    class  SectionAda extends BaseSectionQuickAdapter<SelectCut,BaseViewHolder>
    {


        @Override
        protected void convert(BaseViewHolder holder, SelectCut selectCut) {
                     holder.setText(R.id.name,selectCut.t.getName())
                             .setText(R.id.age, selectCut.t.age);



        }

        public SectionAda(List<SelectCut> data) {
            super(R.layout.section_convert, R.layout.section_head, data);
        }

        @Override
        protected void convertHead(BaseViewHolder baseViewHolder, SelectCut selectCut) {
                              baseViewHolder.setText(R.id.head, selectCut.header);
        }
    }



}
